// pages/orderov/orderov.js
var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    actives: 1,
    listInfowrite: '',
    listInfoPages: '',
    statusd: 1
  },
  onLoad: function(options) {
    var _this = this
    _this.writeoffOrder('today')
    setTimeout(() => {
      _this.setData({
        statusd: 0
      })
    }, 1500)
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {
    var _this = this
    _this.showList()
  },
  //点击加载数据
  showList(e) {
    var _this = this,
      lists = _this.data.listInfowrite
    let orderPage = _this.data.listInfoPages
    if (!orderPage) {
      console.log('没有更多数据了')
      wx.showToast({
        title: '没有更多数据了',
        icon: 'none'
      })
    } else {
      com.link(orderPage, {}, function(rep) {
        console.log(rep)
        for (let i in rep.data.data) {
          list.push(rep.data.data[i])
        }
        _this.setData({
          listInfowrite: list,
          listInfoPages: rep.data.links.next
        })
      }, "GET")
    }
  },
  // onShareAppMessage: function() {},
  //获取核销订单列表
  writeoffOrder(e) {
    var _this = this
    com.link(app.link.writeoffOrder, {
      tab: e
    }, function(rep) {
      console.log(rep);
      _this.setData({
        listInfowrite: rep.data.data,
        listInfoPages: rep.data.links.next
      })
    }, "Get")
  },
  //切换‘核销订单’ ‘商品订单’
  orderTab: function(e) {
    var _this = this,
      o = e.currentTarget.dataset.index
    _this.setData({
      actives: o,
    })
    if (o == 1) {
      var e = 'today'
    } else if (o == 2) {
      var e = 'three'
    } else if (o == 3) {
      var e = 'month'
    } else if (o == 4) {
      var e = ''
    }
    wx.setStorageSync('e', e)
    _this.writeoffOrder(e)
  },
})